﻿using System;
using System.Windows.Forms;

namespace FWF.Logging.Viewer.Style
{
    /// <summary>
    /// 
    /// </summary>
    public class WindowStyleManager
    {
        private static volatile Win8Style _win8 = new Win8Style();
        private static volatile Win7Style _win7 = new Win7Style();
        private static volatile VistaStyle _vista = new VistaStyle();
        private static volatile WinXpStyle _winXp = new WinXpStyle();

        #region Constructors / Finalizer

        /// <summary>
        /// Initializes a new instance of the <see cref="WindowStyleManager"/> class.
        /// </summary>
        protected WindowStyleManager()
        {
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets the current.
        /// </summary>
        /// <value>The current.</value>
        public static IWindowStyle Current
        {
            get
            {
                bool bIsWin8 = Environment.OSVersion.Version.Major >= 8;
                bool bIsWin7 = Environment.OSVersion.Version.Major >= 7;
                bool bIsVista = Environment.OSVersion.Version.Major >= 6;

                // Only execute formatting if not in design mode, and OS supports it
                if ( bIsWin8 )
                {
                    return _win8;
                }
                if ( bIsWin7 )
                {
                    return _win7;
                }
                if ( bIsVista )
                {
                    return _vista;
                }
                
                return _winXp;
            }
        }

        #endregion

        /// <summary>
        /// Applies the style.
        /// </summary>
        /// <param name="ctrl">The Control.</param>
        public static void ApplyStyle( Control ctrl )
        {
            //
            ctrl.SuspendLayout();

            //
            ctrl.Font = Current.DefaultFont;

            //
            ctrl.ResumeLayout( true );
            ctrl.PerformLayout();
        }

    }

}
